﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
    DataTable dt=new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            dt = new DataTable();
            dt.Columns.Add("mavt");
            dt.Columns.Add("soluong");
            dt.Columns.Add("dongia");
            dt.Columns.Add("tien");
           
        }
        if (Session["table"] != null)
        {
            dt =(DataTable) Session["table"];
        }
        loadGirdview();
       
    }
    public void loadGirdview(){
        gv_chi_tiet_hoa_don.DataSource = dt;
        gv_chi_tiet_hoa_don.DataBind();
    }
    protected void btadd_Click(object sender, EventArgs e)
    {
        DataRow newRow = dt.NewRow();
        newRow["mavt"] = txtmavt.Text;
        newRow["soluong"] = txtsolong.Text;
        newRow["dongia"] = txtdongia.Text;
        newRow["tien"] = txttien.Text;
        dt.Rows.Add(newRow);
        Session["table"] = dt;
        loadGirdview();
    }
    protected void btsubmit_Click(object sender, EventArgs e)
    {
        String s;

        s = "<root><Hoadon maKhach=\"long\" sotien=\"34\" soluong=\"324\"></Hoadon>";
        String s1 = "<Chitiethoadon mahoadon=\"1\" mavt=\"1\" soluong=\"2\" dongia=\"3\" tien=\"34\"></Chitiethoadon>";
        s = s + s1;
        s1 = "<Chitiethoadon mahoadon=\"1\" mavt=\"3\" soluong=\"3\" dongia=\"3\" tien=\"34\"></Chitiethoadon>";
        s = s + s1;
        s = s + "</root>";
        dataservice data = new dataservice();
        SqlConnection conn = data.getconnect();
        SqlCommand cmd = new SqlCommand("sp_tbl_hoa_don_insert", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@doc", s));
        cmd.ExecuteNonQuery();
        conn.Close();
        
    }
    protected void btxoa_Click(object sender, EventArgs e)
    {
        String s;
            s="<root><Chitiethoadon ma=\"5\"></Chitiethoadon><Chitiethoadon ma=\"4\"></Chitiethoadon></root>";
            dataservice data = new dataservice();
            SqlConnection conn = data.getconnect();
            SqlCommand cmd = new SqlCommand("sp_tbl_chi_tiet_hoa_don_delete", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@doc", s));
            cmd.ExecuteNonQuery();
            conn.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String s;
        s = "<root><Chitiethoadon ma=\"7\" mahoadon=\"1\" mavt=\"1\" soluong=\"299\" dongia=\"1\" tien=\"314\"></Chitiethoadon> <Chitiethoadon ma=\"5\" mahoadon=\"1\" mavt=\"1\" soluong=\"1\" dongia=\"31\" tien=\"111\"></Chitiethoadon></root>";
        dataservice data = new dataservice();
        SqlConnection conn = data.getconnect();
        SqlCommand cmd = new SqlCommand("sp_tbl_chi_tiet_hoa_don_update", conn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@doc", s));
        cmd.ExecuteNonQuery();
        conn.Close();
    }
}